﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

using CE.Configuration;
using CE.Global;
using CE.User;
using CE.Image;
using CE.CarInsurance;
using CE.Mail;
using CE.Company;
using CE.Database;

public partial class car_insurance_car_details : MyLanguageAndSessionBasePage
{
    CE.User.Profile _profile = null;
    CE.User.ProfileDB _profiledb = null;
    Contact _contact = null;
    ContactDB _contactdb = null;
    string _redirectUrl = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.Page.Title = Resources.Title.CITitle;

        LiteralControl newln = new LiteralControl(Environment.NewLine);
        HtmlMeta language = new HtmlMeta();
        language.Name = "language";
        language.Content = Resources.Title.PageLanguage;

        HtmlMeta keywords = new HtmlMeta();
        keywords.Name = "keywords";
        keywords.Content = Resources.Title.CIKeyword;
        HtmlMeta description = new HtmlMeta();
        description.Name = "description";
        description.Content = Resources.Title.CIDescription;

        Page.Header.Controls.AddAt(10, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(11, language);
        Page.Header.Controls.AddAt(12, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(13, keywords);
        Page.Header.Controls.AddAt(14, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(15, description);

        if (!Page.IsPostBack)
        {
            if (Request.Params["lang"] != null)
            {
                if (Request.Params["lang"].ToString() != "th-TH")
                {
                    litZopim.Visible = true;
                }
                else
                {
                    litZopim.Visible = false;
                }
            }
            Session["CIMSG"] = null;
            Session["UMMSG"] = null;
            LoadManufactYearList();
            ClearAllList();
            SetCoverageComDate();
            ddlManufactYear.Attributes.Add("onblur", "ShowValidationEffect('" + ddlManufactYear.ClientID + "','" + rfvManufactYear.ClientID + "');");
            ddlCarMake.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCarMake.ClientID + "','" + rfvCarMake.ClientID + "');");
            ddlModelBodyCCDoor.Attributes.Add("onblur", "ShowValidationEffect('" + ddlModelBodyCCDoor.ClientID + "','" + rfvModelBodyCCDoor.ClientID + "');");
            ddlCoverageComDate.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCoverageComDate.ClientID + "','" + rfvCoverComDate.ClientID + "');");
            ddlCoverageComMonth.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCoverageComMonth.ClientID + "','" + rfvCoverComMonth.ClientID + "');");
            
            Page.Form.DefaultButton = btnNext.UniqueID;

            General.ClearAllSession(this.Page, "CI");

            if (Session[General.UserId] != null)
            {
                ShowCustomerDetail(Convert.ToInt64(Session[General.UserId]));
                lbnLoginPopup.Visible = false;
            }
        }
        else
        {
            if (vsCarProfile.Enabled == false) vsCarProfile.Enabled = true;
        }
        ClickOnceButton(this.Page, this.btnNext);
    }

    private string EmailAddress
    {
        get { return txtEmailAddress.Text.Trim(); }
    }

    private void ShowCustomerDetail(Int64 UserId)
    {
        _profile = new CE.User.Profile();
        _profiledb = new ProfileDB();
        _contact = new Contact();
        _contactdb = new ContactDB();

        _profile = _profiledb.GetProfile(UserId);
        _profiledb = null;

        if (_profile != null)
        {
            txtName.Text = _profile.FirstName;

            if (_profile.SurName != string.Empty)
            {
                txtName.Text += " " + _profile.SurName;
            }
            _contact = _contactdb.GetContact(UserId);
            if (_contact != null)
            {
                SetEmailAddress(_contact.Email);
                txtEmailAddress.ReadOnly = true;
          
                txtMobileNo.PhoneNo = _contact.Mobile;
            }
            _profile = null;
            checkIsAgreement.Visible = false;
            lblAgreement.Visible = false;
        }
    }

    private void SetEmailAddress(string emailaddress)
    {
        txtEmailAddress.Text = emailaddress;
       
    }

    private void LoadManufactYearList()
    {
        int _yearCount = 14;
        ddlManufactYear.Items.Clear();

        int _startYear = General.GetUTCDateTime().Year - _yearCount;
        int _endYear = General.GetUTCDateTime().Year - 1;
        for (int i = _endYear; i >= _startYear; i--)
        {
            if (CultureInfo.CurrentCulture.Name != "th-TH")
            {
                ddlManufactYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
            else
            {
                ddlManufactYear.Items.Add(new ListItem(i.ToString() + " - พ.ศ. " + (i + 543).ToString(), i.ToString()));
            }
        }
        ddlManufactYear.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        try
        {
            ChangeValidationEffectServerSide("carprofile");


            Page.Validate("carprofile");
            if (Page.IsValid)
            {
                bool _IsEmailExist = false;
                if (Session[General.UserId] == null)
                {
                    Account _useraccount = new Account();
                    AccountDB _useraccountdb = new AccountDB();

                    if (_useraccountdb.IsAlreadyExist(EmailAddress, Convert.ToInt32(CE.Global.CEUserType.Customer))) //txtEmailAddress.Text.Trim()
                    {
                        txtEmailAddress.ControlStyle.CssClass = "validationError";
                        txtExEmail.Text = txtEmailAddress.Text.Trim();
                        lblMessage.Text = "";
                        vsCarProfile.Enabled = false;
                        _IsEmailExist = true;
                        mpePassword.Show();
                        return;
                    }
                }
                vsCarProfile.Enabled = true;
                if (_IsEmailExist == false && Save())
                {
                    Int64 _userId = 0;
                    Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());
                    bool _newuser = false;
                    if (Session[General.UserId] != null)
                    {
                        _userId = Convert.ToInt64(Session[General.UserId].ToString());
                    }
                    else
                    {
                        _newuser = true;
                    }

                    if (UpdateProfile(_userId, _carId) > 0)
                    {
                        if (_newuser)
                        {
                            SendMailToUser(EmailAddress, Session[CE.Global.General.UserName].ToString(), txtMobileNo.GetPhoneNo()); //txtEmailAddress.Text.Trim()
                        }

                        Session["CLASSTYPE"] = "1";
                        lblMessage.Text = "Saved successfully!";
                        Session["FROMCARDETAIL"] = "1";
                        _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/quote-results.aspx", Page);
                        Response.Redirect(_redirectUrl);
                    }
                    else
                    {
                        lblMessage.Text = "";
                        vsCarProfile.Enabled = false;
                        mpePassword.Show();
                    }
                }
                else
                {
                    lblMessage.Text = "Saving did NOT succeed!";
                }
            }
            else
            {
                lblMessage.Text = "Please fill all require fields completly and correctly.";
            }
        }
        catch
        { }
        finally
        {
            ddlManufactYear.Enabled = true;
            ddlCarMake.Enabled = true;
            ddlModelBodyCCDoor.Enabled = true;
            ddlCoverageComMonth.Enabled = true;
        }
    }

    private void ClickOnceButton(Page page, Button b)
    {
        System.Text.StringBuilder oneClickScript = new System.Text.StringBuilder();
        oneClickScript.Append("if (typeof(Page_ClientValidate) == 'function') { ");
        oneClickScript.Append("if (Page_ClientValidate() == false) { return false; }} ");
        oneClickScript.Append("this.value = 'Processing...';");
        oneClickScript.Append("this.disabled = true;");
        oneClickScript.Append(page.ClientScript.GetPostBackEventReference(b, ""));
        oneClickScript.Append(";");
        b.Attributes.Add("onclick", oneClickScript.ToString());
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        txtName.Text = CE.Global.General.ClearScriptTag(txtName.Text.Trim());
        txtSumInsured.Text = HttpUtility.HtmlEncode(txtSumInsured.Text);
        txtNewSumInsured.Text = HttpUtility.HtmlEncode(txtNewSumInsured.Text);
        txtMobileNo.PhoneNo = HttpUtility.HtmlEncode(txtMobileNo.PhoneNo);
        txtGroupNo.Text = HttpUtility.HtmlEncode(txtGroupNo.Text);
        
        //Year of Manufaturer
        if (rfvManufactYear.Enabled && rfvManufactYear.ValidationGroup == strValidationGroup)
        {
            rfvManufactYear.Validate();
            if (rfvManufactYear.IsValid == false)
            {
                ddlManufactYear.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlManufactYear.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlManufactYear.ControlStyle.CssClass = "";
        }

        if (rfvCarMake.Enabled && rfvCarMake.ValidationGroup == strValidationGroup)
        {
            rfvCarMake.Validate();
            if (rfvCarMake.IsValid == false)
            {
                ddlCarMake.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCarMake.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCarMake.ControlStyle.CssClass = "";
        }

        if (rfvModelBodyCCDoor.Enabled && rfvModelBodyCCDoor.ValidationGroup == strValidationGroup)
        {
            rfvModelBodyCCDoor.Validate();
            if (rfvModelBodyCCDoor.IsValid == false)
            {
                ddlModelBodyCCDoor.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlModelBodyCCDoor.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlModelBodyCCDoor.ControlStyle.CssClass = "";
        }

        //Cover Commencement Date
        if (rfvCoverComDate.Enabled && rfvCoverComDate.ValidationGroup == strValidationGroup)
        {
            rfvCoverComDate.Validate();
            if (rfvCoverComDate.IsValid == false)
            {
                ddlCoverageComDate.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCoverageComDate.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCoverageComDate.ControlStyle.CssClass = "";
        }

        if (revName.Enabled && revName.ValidationGroup == strValidationGroup)
        {
            
            revName.Validate();
            if (revName.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }

        //Mobile No
        txtMobileNo.ChangeValidationEffectServerSide(strValidationGroup);

    }

    private bool Save()
    {
        Int64 _carresult = 0;
        Int64 _policyresult = 0;

        CarDetailTH _car = new CarDetailTH();
        CarDetailTHDB _cardb = new CarDetailTHDB();

        ProfileDB _profiledb = new ProfileDB();
        Profile _profile = new Profile();

        Contact _contact = new Contact();
        ContactDB _contactdb = new ContactDB();

        Int64 _refceuserid = 0;

        if (Session[General.CarId] != null)
        {
            _car = _cardb.GetCar(Convert.ToInt64(Session[General.CarId].ToString()), 0);
            if (Session[General.AgentId] != null)
            {
                _car.Info5 = "UPDATE";
            }
        }
        else
        {
            if (Session[General.AgentId] != null)
            {
                _car.Info4 = "NEW";
            }
        }
        if (_car == null)
        {
            _car = new CarDetailTH();
        }
        if (Session[CE.Global.General.UserId] != null)
        {
            _refceuserid = Convert.ToInt64(Session[CE.Global.General.UserId]);
            _profile = _profiledb.GetProfile(_refceuserid);
            _contact = _contactdb.GetContact(_refceuserid);
            if (_profile != null && _contact != null)
            {
                _car.Info5 = _contact.Email;
                _car.Info6 = _contact.Mobile;
                _car.Info7 = _profile.SurName;
                if (_profile.FirstName.Trim().Length > 0)
                {
                    _car.Info8 = _profile.FirstName;//txtFirstName.Text.Trim();
                }
                _car.Info9 = (_profile.Gender.ToString().Trim() != "" ? _profile.Gender.ToString() : "M"); //ddlGender.GetGender();
                if (_profile.DOB.Year == 1900)
                {
                    DateTime dteDOB = new DateTime(1995, 1, 1);
                    _car.Info10 = dteDOB.ToString("dd-MMM-yyyy");
                }
                else
                {
                    _car.Info10 = _profile.DOB.ToString("dd-MMM-yyyy"); //usrDOB.GetDate().ToString("dd-MMM-yyyy");
                }
                _car.Info11 = _profile.Occupation.ToString();// ddlOccupation.GetOccupation();
                _car.Info12 = _profile.JobNature;//ddlJobNature.GetJobNature();
                _car.Info13 = _profile.MaritalStatus.ToString();//ddlMaritalStatus.GetMaritalStatus();
                _car.Info14 = "0"; //ddlYearDriveSg.Text;
                _car.Info15 = _profile.Salutation;//ddlSalutation.GetSalutation();
                _profile = null;
                _contact = null;
            }
        }

        _car.ManufactYear = Convert.ToInt32(ddlManufactYear.Text);

        if (Session[General.AgentId] != null)
        {
            _car.Info2 = Session[General.AgentId].ToString();
            _car.Info3 = General.GetUTCDateTime().ToString();
        }

        _car.CarMakeName = ddlCarMake.Text;//Convert.ToInt32(txtCarMakeId.Text);
        string[] _tempDesc = ddlModelBodyCCDoor.Text.Split(' ');
        if (_tempDesc.Length == 5)
        {
            _car.CarModelName = _tempDesc[0];
            _car.Body = _tempDesc[1];
            _car.CC = Convert.ToInt32(_tempDesc[2].Substring(0, _tempDesc[2].Length - 2));
            _car.Door = Convert.ToInt32(_tempDesc[3]);
        }
        else if (_tempDesc.Length == 6)
        {
            _car.CarModelName = _tempDesc[0] + " " + _tempDesc[1];
            _car.Body = _tempDesc[2];
            _car.CC = Convert.ToInt32(_tempDesc[3].Substring(0, _tempDesc[3].Length - 2));
            _car.Door = Convert.ToInt32(_tempDesc[4]);
        }
        else if (_tempDesc.Length == 7)
        {
            _car.CarModelName = _tempDesc[0] + " " + _tempDesc[1] + " " + _tempDesc[2];
            _car.Body = _tempDesc[3];
            _car.CC = Convert.ToInt32(_tempDesc[4].Substring(0, _tempDesc[4].Length - 2));
            _car.Door = Convert.ToInt32(_tempDesc[5]);
        }
        _car.GroupNo = Convert.ToInt32(txtGroupNo.Text);
        _car.Info2 = lblCarVehicleType.Text;
        
        //LC = 210 or 220
        //PS = 110 or 120
        //PU = 320
        //SV = 110 or 120
        if (lblCarVehicleType.Text == "PS" || lblCarVehicleType.Text == "SV" || lblCarVehicleType.Text == "")
        {
            _car.Info3 = "110";
        }
        else if (lblCarVehicleType.Text == "LC")
        {
            _car.Info3 = "210";
        }
        else if (lblCarVehicleType.Text == "PU")
        {
            if (_car.Door == 4)
                _car.Info3 = "110";
            else
                _car.Info3 = "320";
        }

        //_car.Info3 = ddlVehicleType.Text;
        _car.MakeModelDesc = ddlCarMake.SelectedItem.Text + " " + ddlModelBodyCCDoor.SelectedItem.Text;
        _car.Status = true;
        _car.RefCEUserId = _refceuserid;
        //_car.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
        _car.CurrentStep = 1;
        _car.TotalStep = 4;

        // 03/2013
        _car.Info1 = "150"; // = อื่นๆ  //ddlCurInsuranceCompany.Text; //Current Insurer ID

        _carresult = _cardb.Insert(_car);

        _car = null;
        _cardb = null;
        //_profile = null;
        //_profiledb = null;

        if (_carresult > 0)
        {
            Session[CE.Global.General.CarId] = _carresult.ToString();
        }
        else
        {
            lblMessage.Text = "Insert error!";
        }
        //return _result > 0;
        if (_carresult > 0)
        {
            //CAR POLICY DETAILS
            CarPolicy _carpolicy = new CarPolicy();
            CarPolicyDB _carpolicydb = new CarPolicyDB();
            Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());

            Int64 _carpolicyid = 0;

            if (Session[General.CarPolicyId] != null)
            {
                _carpolicyid = Convert.ToInt64(Session[General.CarPolicyId].ToString());
                _carpolicy.CECarPolicyId = _carpolicyid;
                if (Session[General.AgentId] != null)
                {
                    _carpolicy.Info5 = "UPDATE";
                }
            }
            else
            {
                if (Session[General.AgentId] != null)
                {
                    _carpolicy.Info4 = "NEW";
                }
            }

            lblMessage.Text = "";
            if (Session[General.AgentId] != null)
            {
                _carpolicy.Info2 = Session[General.AgentId].ToString();
                _carpolicy.Info3 = General.GetUTCDateTime().ToString();
            }
            _carpolicy.CECarId = _carId;
            // 03/2013
            _carpolicy.InsuranceType = 10; //Convert.ToInt32(ddlInsuranceType.Text);
            _carpolicy.GarageType = Convert.ToInt32("1");
            _carpolicy.VehicleType = Convert.ToInt32("110");
            _carpolicy.SumInsured = Convert.ToInt32(txtSumInsured.Text);
            _carpolicy.ProvinceRegistration = "BKK"; //ddlProvinceRegistration.Text;
            _carpolicy.UseOfVehicle = "N/A";//ddlUseOfVehicle.Text;
            string strDate = ddlCoverageComDate.Text;
            int _iDay = Convert.ToInt32(strDate.Substring(0, 2));
            strDate = ddlCoverageComMonth.Text;
            int _iMonth = Convert.ToInt32(strDate.Substring(0, 2));
            int _iYear = Convert.ToInt32(strDate.Substring(2, 4));
            _carpolicy.CoverageCommenceDate = new DateTime(_iYear, _iMonth, _iDay); //DateTime.Today.AddDays(14);
            _carpolicy.IsRedPlate = false; //rdoYesRedPlate.Checked;

            _carpolicy.IsAddAccMod = false;
            _carpolicy.AddAccModAmount = 0;
            _carpolicy.NCDPercent = Convert.ToInt32("20");
            _carpolicy.IsClaimLastYear = false;
            _carpolicy.IsCTPL = false;

            _carpolicy.IsAddDriver = false;
            _carpolicy.NoOfDriver = 0;
            _carpolicy.Deductible = Convert.ToInt16("-1");
            _carpolicy.CurrentInsurer = Resources.CarInsurance.Others; //ddlCurInsuranceCompany.SelectedItem.Text;
            _carpolicy.RefCEUserId = _refceuserid;
            _carpolicy.Status = true;
            _carpolicy.CurrentStep = 2;
            _policyresult = _carpolicydb.Insert(_carpolicy);
            if (_policyresult > 0)
            {
                Session[General.CarPolicyId] = _policyresult.ToString();

                lblMessage.Text += "<br>Car policy saved successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblMessage.Text = "Car policy did not save successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                return false;
            }
            CarDriver _cardriver = new CarDriver();
            CarDriverDB _cardriverdb = new CarDriverDB();

            _cardriverdb.UpdateAllStatus(_carId, _refceuserid);

            _carpolicy = null;
            _carpolicydb = null;
        }

        return _policyresult > 0;
    }

    private Int64 UpdateProfile(Int64 UserId, Int64 CarId)
    {
        Int64 _retValue = 0;

        if (UserId != 0)
        {
            _profile = new CE.User.Profile();
            _profiledb = new ProfileDB();

            _contact = new Contact();
            _contactdb = new ContactDB();

            _profile = _profiledb.GetProfile(UserId);
            _contact = _contactdb.GetContact(UserId);

            if (_profile != null)
            {
                #region Update Profile
                
                _profile.Salutation = ""; // ddlSalutation.GetSalutation();
                txtName.Text = CE.Global.General.ClearScriptTag(txtName.Text.Trim());
                _profile.FirstName = HttpUtility.HtmlEncode(txtName.Text);
                _profile.SurName = ""; //txtSurName.Text;
                if (_profile.DOB.Year == 1900)
                {
                    DateTime dteDOB = new DateTime(1995, 1, 1);
                    _profile.DOB = dteDOB;
                }
                if (_profile.Gender.ToString().Trim() == "")
                {
                    _profile.Gender = 'M'; //Convert.ToChar(ddlGender.GetGender());
                }
                 _profile.Status = "Complete";

                _retValue = _profiledb.Insert(_profile);

                if (_retValue > 0 && _contact != null)
                {
                    _contact.Mobile = txtMobileNo.GetPhoneNo();
                    _contact.Status = true;

                    _retValue = _contactdb.Insert(_contact);
                }
                else
                {
                }

                if (_retValue > 0)
                {
                    if (_profile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = _profile.FirstName + " " + _profile.SurName;
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = _profile.SurName;
                    }
                    Session[General.UserPhoneNo] = txtMobileNo.GetPhoneNo();
                    Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                    if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                        Convert.ToInt32(CE.Global.CEUserType.Provider))
                    {
                        Session[CE.Global.General.ProviderProfileFirstTime] = "0";
                    }
                }
                else
                {
                }

                _profile = null;
                _contact = null;
                #endregion
            }
        }
        else
        {
            _retValue = SaveNewCustomer();
            UserId = _retValue;
        }

        if (_retValue > 0)
        {
            CarDetailTH _cardetail = new CarDetailTH();
            CarDetailTHDB _cardetaildb = new CarDetailTHDB();
            _cardetail = _cardetaildb.GetCar(CarId, UserId);


            _profile = new CE.User.Profile();
            _profiledb = new ProfileDB();
            _profile = _profiledb.GetProfile(UserId);

            if (_cardetail != null)
            {
                _cardetail.Info5 = EmailAddress; //txtEmailAddress.Text;
                _cardetail.Info6 = txtMobileNo.GetPhoneNo();
                _cardetail.Info7 = ""; //txtSurName.Text.Trim();
                txtName.Text = CE.Global.General.ClearScriptTag(txtName.Text.Trim());
                if (txtName.Text.Trim().Length > 0)
                {
                    _cardetail.Info8 = Server.HtmlEncode(txtName.Text.Trim());
                }
                if (_profile.Gender.ToString().Trim() != "")
                {
                    _cardetail.Info9 = _profile.Gender.ToString(); //ddlGender.GetGender();
                }
                else
                {
                    _cardetail.Info9 = "M"; //ddlGender.GetGender();
                }
                if (_profile.DOB.Year == 1900)
                {
                    DateTime dteDOB = new DateTime(1995, 1, 1);
                    _cardetail.Info10 = dteDOB.ToString("dd-MMM-yyyy"); //usrDOB.GetDate().ToString("dd-MMM-yyyy");
                }
                else
                {
                    _cardetail.Info10 = _profile.DOB.ToString("dd-MMM-yyyy");
                }
                _cardetail.Info11 = _profile.Occupation.ToString(); //Resources.CarInsurance.CorporateEmployee; //ddlOccupation.GetOccupation();
                _cardetail.Info12 = "";// ddlJobNature.GetJobNature();
                _cardetail.Info13 = "";// ddlMaritalStatus.GetMaritalStatus();
                _cardetail.Info14 = "";// ddlYearDriveSg.Text;
                _cardetail.Info15 = "";// ddlSalutation.GetSalutation();
                _cardetail.RefCEUserId = UserId;
            }
            _profile = null;

            //RefUserId only update
            CarPolicy _carpolicy = new CarPolicy();
            CarPolicyDB _carpolicydb = new CarPolicyDB();
            _carpolicy = _carpolicydb.GetCarPolicy(CarId, UserId);
            _carpolicy.RefCEUserId = UserId;

            _retValue = _cardetaildb.Insert(_cardetail);

            _retValue = _carpolicydb.Insert(_carpolicy);

            //update RefIds
            CarDetailTHDB cardb = new CarDetailTHDB();
            cardb.UpdateCarDetailPolicy(CarId, UserId);

            if (_retValue <= 0)
            {
            }
        }

        return _retValue;
    }

    private Int64 SaveNewCustomer()
    {
        #region New Customer
        Int64 _retVal = 0;
        if (Page.IsValid)
        {

            Account _useraccount = new Account();
            AccountDB _useraccountdb = new AccountDB();

            if (_useraccountdb.IsAlreadyExist(EmailAddress, Convert.ToInt32(CE.Global.CEUserType.Customer))) //txtEmailAddress.Text.Trim()
            {
                txtEmailAddress.ControlStyle.CssClass = "validationError";
                _retVal = 0;
            }
            else
            {
                Profile _userprofile = new Profile();
                ProfileDB _userprofiledb = new ProfileDB();
                Contact _contact = new Contact();
                ContactDB _contactdb = new ContactDB();

                long _result = -1;

                _useraccount.Email = EmailAddress.ToLower(); 
                string _authcode = txtMobileNo.GetPhoneNo();
                _useraccount.AuthCode = _authcode;
                _useraccount.UserId = "CEUSERAUTOIDCI";
                _useraccount.UserTypeId = Convert.ToInt32(CE.Global.CEUserType.Customer);
                _useraccount.IsAcceptTC = false;
                _useraccount.Status = true;
                _useraccount.RefCEUserID = -1;
                _result = _useraccountdb.Insert(_useraccount);
                _useraccount.CEID = _result;
                _retVal = _useraccount.CEID;
                if (_result > 0)
                {
                    _userprofile.Salutation = ""; //ddlSalutation.GetSalutation();
                    _userprofile.FirstName = Server.HtmlEncode(txtName.Text);
                    _userprofile.SurName = "";
                    DateTime dteDOB = new DateTime(1995, 1, 1);
                    _userprofile.DOB = dteDOB;
                    _userprofile.Gender = 'M'; //Convert.ToChar(ddlGender.GetGender());

                    _userprofile.Occupation = Convert.ToInt32("54");
                    _userprofile.Status = "Complete";
                    _userprofile.RefCEUserId = _useraccount.CEID;
                    _userprofile.IsAcceptTC = checkIsAgreement.Checked;
                    _result = _userprofiledb.Insert(_userprofile);

                    _contact.Email = _useraccount.Email;
                    _contact.Mobile = txtMobileNo.GetPhoneNo();

                    _contact.Status = true;
                    _contact.RefCEUserId = _useraccount.CEID;
                    _result = _contactdb.Insert(_contact);

                    if (_result > 0)
                    {
                        Session[CE.Global.General.UserId] = _useraccount.CEID;
                        Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                        Session[CE.Global.General.UserEmail] = _useraccount.Email;
                        Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                        Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                        if (_userprofile.FirstName != string.Empty)
                        {
                            Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                        }
                        else
                        {
                            Session[CE.Global.General.UserName] = _userprofile.SurName;
                        }
                        Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                    }

                }

            }
        }
        else
        {
            _retVal = 0;
        }

        return _retVal;
        #endregion
    }

    private bool SendMailToUser(string EmailAddress, string UserName, string AuthCode)
    {
        bool _retVal = false;
        _retVal = CE.Email.Welcome.SendMail(EmailAddress, UserName, AuthCode);
        return _retVal;
    }

    #region Car

    protected void ddlManufactYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            string carMakeValue = ddlCarMake.Text;
            string carModelValue = ddlModelBodyCCDoor.Text;

            if (ddlManufactYear.Text == "-1")
            {
                ClearAllList();
                divCarModel.Style.Add("display", "none");
            }
            else
            {
                GetCarMakeList(ddlManufactYear.Text, ddlCarMake);
                if (ddlCarMake.Items.Count > 0)
                {
                    if (carMakeValue != "-1")
                    {
                        ddlCarMake.Text = carMakeValue;
                        ddlCarMake_SelectedIndexChanged(sender, e);

                        if (carModelValue != "-1" && ddlModelBodyCCDoor.Items.Count > 0)
                        {
                            ddlModelBodyCCDoor.Text = carModelValue;
                            ddlModelBodyCCDoor_SelectedIndexChanged(sender, e);
                        }
                    }
                    else
                    {
                    }
                }
            }
        }
        catch
        {

        }
    }

    protected void ddlCarMake_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCarMake.Text == "-1")
        {
            ddlModelBodyCCDoor.Items.Clear();
            ddlModelBodyCCDoor.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
            divCarModel.Style.Add("display", "none");
            txtSumInsured.Text = "0";
            lblSumInsured.Text = "0";
            txtGroupNo.Text = "-1";
        }
        else
        {
            GetCarModelDescList(ddlCarMake.Text, ddlManufactYear.Text, ddlModelBodyCCDoor);
            if (ddlModelBodyCCDoor.Items.Count > 0)
            {
                ddlModelBodyCCDoor.SelectedIndex = 0;
                ddlModelBodyCCDoor_SelectedIndexChanged(sender, e);
            }

            divCarModel.Style.Add("display", "");
        }
    }

    private void ClearAllList()
    {
        ddlCarMake.Items.Clear();
        ddlCarMake.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
        ddlModelBodyCCDoor.Items.Clear();
        ddlModelBodyCCDoor.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    private void GetCarMakeList(string Year, DropDownList ddlList)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblMake");
        SortedList _spList = new SortedList();
        _spList.Add("@Year", Year);
        _dt = _db.GetDataTableBySP("sprocGetCarMakeTHListByYear", _spList);
        ddlList.Items.Clear();
        ddlList.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        if (_dt != null && _dt.Rows.Count > 0)
        {
            for (int i = 0; i < _dt.Rows.Count; i++)
            {
                ddlList.Items.Add(new ListItem(_dt.Rows[i][1].ToString(), _dt.Rows[i][0].ToString()));
            }
        }

        _dt = null;
        _db = null;
    }

    private void GetCarModelDescList(string CarMake, string Year, DropDownList ddlList)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelDesc");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@Year", Year);
        _dt = _db.GetDataTableBySP("sprocGetCarModelDescTHListByCarMakeCode", _spList);
        ddlList.Items.Clear();
        ddlModelBodyCCDoor.Items.Clear();
        ddlModelBodyCCDoor.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
        if (_dt != null && _dt.Rows.Count > 0)
        {
            ddlModelBodyCCDoor.DataSource = _dt;
            ddlModelBodyCCDoor.DataValueField = "CarModelDesc";
            ddlModelBodyCCDoor.DataTextField = "CarModelDisplay";
            ddlModelBodyCCDoor.DataBind();
            ddlModelBodyCCDoor.Items.Insert (0,new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        else
        {
            ddlList.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        _dt = null;
        _db = null;
    }

    protected void ddlModelBodyCCDoor_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlManufactYear.SelectedIndex >= 0 && ddlCarMake.SelectedIndex >= 0 & ddlModelBodyCCDoor.SelectedIndex >= 0)
        {
            string[] _tempDesc = ddlModelBodyCCDoor.Text.Split(' ');
            string _model = "";
            string _body = "";
            string _cc = "";
            string _door = "";
            if (_tempDesc.Length == 4)
            {
                _model = _tempDesc[0];
                _body = "-";// _tempDesc[2] == "2" ? "PICKUP" : "";
                _cc = _tempDesc[1].Substring(0, _tempDesc[1].Length - 2);
                _door = _tempDesc[2];
            }
            else if (_tempDesc.Length == 5)
            {
                _model = _tempDesc[0];
                _body = _tempDesc[1];
                _cc = _tempDesc[2].Substring(0, _tempDesc[2].Length - 2);
                _door = _tempDesc[3];
            }
            else if (_tempDesc.Length == 6)
            {
                _model = _tempDesc[0] + " " + _tempDesc[1];
                _body = _tempDesc[2];
                _cc = _tempDesc[3].Substring(0, _tempDesc[3].Length - 2);
                _door = _tempDesc[4];
            }
            else if (_tempDesc.Length == 7)
            {
                _model = _tempDesc[0] + " " + _tempDesc[1] + " " + _tempDesc[2];
                _body = _tempDesc[3];
                _cc = _tempDesc[4].Substring(0, _tempDesc[4].Length - 2);
                _door = _tempDesc[5];
            }
            lblModelDesc.Text = "model : " + _model + ", body: " + _body + ", cc: " + _cc + ", door: " + _door;
            GetCarModelSumInsuredAmountAndVehicleType(ddlCarMake.Text, _model, _body, _cc, _door, ddlManufactYear.Text, txtSumInsured, lblSumInsured, lblCarVehicleType);
            txtNewSumInsured.Text = txtSumInsured.Text;
            GetCarModelGroupNo(ddlCarMake.Text, _model, _body, _cc, _door, txtGroupNo);
        }
    }

    private void GetCarModelGroupNo(string CarMake, string CarModel, string Body, string CC, string Door, TextBox txtTextBox)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelBody");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@CarModel", CarModel);
        _spList.Add("@Body", Body);
        _spList.Add("@CC", CC);
        _spList.Add("@Door", Door);
        _dt = _db.GetDataTableBySP("sprocGetCarModelGroupTH", _spList);

        if (_dt != null && _dt.Rows.Count > 0)
        {
            txtTextBox.Text = _dt.Rows[0][0].ToString();
        }
        else
        {
            txtGroupNo.Text = "-1";
        }
        txtTextBox.ReadOnly = true;
        _dt = null;
        _db = null;
    }

    private void GetCarModelSumInsuredAmountAndVehicleType(string CarMake, string CarModel, string Body, string CC, string Door, string Year, TextBox txtTextBox, Label lblLabel, Label lblLabelTwo)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelBody");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@CarModel", CarModel);
        _spList.Add("@Body", Body);
        _spList.Add("@CC", CC);
        _spList.Add("@Door", Door);
        _spList.Add("@Year", Year);
        _dt = _db.GetDataTableBySP("sprocGetCarModelSumInsuredAndVehicleTypeTHListByYear", _spList);
        if (_dt != null && _dt.Rows.Count > 0)
        {
            txtTextBox.Text = _dt.Rows[0][0].ToString();
            lblLabelTwo.Text = _dt.Rows[0][1].ToString();
            lblLabel.Text = Convert.ToInt32(txtTextBox.Text).ToString("#,000");
        }
        else
        {
            txtTextBox.Text = "0";
            lblLabel.Text = "0";
        }
        txtTextBox.ReadOnly = true;
        _dt = null;
        _db = null;
    }

    #endregion

    #region login existing user

    protected void imgbtnLogin_Click(object sender, EventArgs e)
    {
        if (AutoLogin(100))
        {
            Int64 _userId = 0;

            if (Session[General.UserId] != null)
            {
                _userId = Convert.ToInt64(Session[General.UserId].ToString());

            }

            Int64 _carId = 0;

            if (Session[General.CarId] != null)
            {
                _carId = Convert.ToInt64(Session[General.CarId].ToString());
            }
            else
            {
            }

            if (_userId > 0)
            {
                inputLoginHide.Value = "1";
                CarDetailTHDB cardb = new CarDetailTHDB();
                cardb.UpdateCarDetailPolicy(_carId, _userId);
                vsCarProfile.Enabled = false;
                mpePassword.Hide();
                inputLoginCount.Value = "0";
                Response.Redirect(CE.Global.General.GetUrl("~/car-insurance/car-details.aspx", Page));
                txtName.Text = "sssssss";
            }

        }
        else
        {

            Int32 logincount = Convert.ToInt32(inputLoginCount.Value.Trim());
            inputLoginCount.Value = (logincount + 1).ToString();

            if (logincount == 2)
            {
                inputHideSignal.Value = "1";
            }
            else if (logincount >= 3)
            {
                this.btnPasswordClose_Click(this, null);
            }
            else
            {
                vsCarProfile.Enabled = false;
                mpePassword.Show();
            }
        }
    }

    protected void lbnLoginPopup_Click(object sender, EventArgs e)
    {
        Response.Redirect(CE.Global.General.GetUrl("~/car-insurance/sign-in.aspx", Page));
    }

    protected void btnPasswordClose_Click(object sender, EventArgs e)
    {
        inputLoginCount.Value = "0";
    }

    private bool AutoLogin(int LoginType)
    {
        bool isLoggedin = false;
        AccountStatus _accountstatus = new AccountStatus();
        AccountStatusDB _accountstatusdb = new AccountStatusDB();
        AccountDB _accountdb = new AccountDB();
        //Check Customer Account

        Account _account = _accountdb.GetUserAccount(txtExEmail.Text.ToLower(), Convert.ToInt32(CE.Global.CEUserType.Customer));

        if (_account != null)
        {
            if (CheckUserLoginCached(_account.CEID.ToString()))
            {
                _accountstatus = _accountstatusdb.GetAccountStatus(_account.CEID, 400);

                if (Server.HtmlDecode(txtExAuthCode.Text) == _account.AuthCode)
                {
                    if (_account.Status == true)
                    {
                        isLoggedin = true;

                        if (_account.Info1 == "0")
                        {
                            //Reset Email Fail Message
                            _account.Info1 = "";
                            _account.Info2 = "";
                            _accountdb.Insert(_account);
                        }

                        _accountstatusdb.InsertAccountStatus(_account.CEID, 400, 1);
                        lblEmailMessage.Visible = false;
                        GetUserInformation(_account);
                        //SaveUserLoginInformation(_account.CEID, _account.UserTypeId);
                        CE.Global.General.CreateUpdateUserLoginCached(Page);
                        _account = null;
                    }
                    else
                    {
                        lblEmailMessage.Visible = true;
                        lblEmailMessage.Text = "Your email has been blocked!";
                    }
                }
                else
                {
                    _accountstatusdb.InsertAccountStatus(_account.CEID, 400, 0);
                    lblEmailMessage.Visible = true;
                    lblEmailMessage.Text = Resources.Menu.EmailPasswordIncorrect;//"Email address or password is incorrect.";
                }
            }
            else
            {
                _redirectUrl = CE.Global.General.GetUrl("~/user/usermessage.aspx", Page);
                Session["UMMSG"] = "UM,1993";
                Response.Redirect(_redirectUrl);
            }
        }
        else
        {
            lblEmailMessage.Visible = true;
            lblEmailMessage.Text = Resources.Menu.EmailPasswordIncorrect;
        }

        return isLoggedin;
    }

    private void GetUserInformation(Account _account)
    {
        DateTime dtNow = new DateTime();
        dtNow = General.GetUTCDateTime();
        Session[CE.Global.General.UserId] = _account.CEID;
        Session[CE.Global.General.UserTypeId] = _account.UserTypeId;

        if (_account.UserTypeId == Convert.ToInt32(CE.Global.CEUserType.Provider))
        {
            CE.Provider.ProviderCompanyLink _comlink = new CE.Provider.ProviderCompanyLink();
            CE.Provider.ProviderCompanyLinkDB _comlinkdb = new CE.Provider.ProviderCompanyLinkDB();
            _comlink = _comlinkdb.GetProviderCompanyId(_account.CEID);
            if (_comlink != null)
            {
                Session[CE.Global.General.ProviderCompanyId] = _comlink.ProviderCompanyId;
            }
        }

        Session[CE.Global.General.UserEmail] = _account.Email;
        Session[CE.Global.General.StartTime] = dtNow.ToString();
        bool isProfileComplete = false;
        bool isContactComplete = false;

        ProfileDB _profiledb = new ProfileDB();
        Profile _profile = new Profile();
        Contact _contact = new Contact();
        ContactDB _contactdb = new ContactDB();

        _contact = _contactdb.GetContact(_account.CEID);

        _profile = _profiledb.GetProfile(_account.CEID);

        if (_contact != null)
        {
            isContactComplete = true;
            Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
        }
        else
        {
            Session[CE.Global.General.UserPhoneNo] = null;
        }

        if (_profile != null)
        {
            if (_profile.FirstName != null && _profile.FirstName != string.Empty)
            {
                Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.SurName) + " " + Server.HtmlDecode(_profile.FirstName);
            }
            else
            {
                Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.SurName);
            }

            if (!string.IsNullOrEmpty(_profile.IDType) &&
                !string.IsNullOrEmpty(_profile.IDNo) &&
                _profile.IDNo.Length == 9)
            {
                Session[CE.Global.General.UserICNumber] = _profile.IDType + " " + _profile.IDNo;
            }

            if (_profile.Status.ToLower() == "complete")
            {
                isProfileComplete = true;
            }
            else
            {
                isProfileComplete = false;
            }
        }
        else
        {
            Session[CE.Global.General.UserName] = null;
        }

        if (isProfileComplete && isContactComplete)
        {
            Session[CE.Global.General.UserProfileAndContactComplete] = "1";
        }
        else
        {
            Session[CE.Global.General.UserProfileAndContactComplete] = "0";
        }

    }

    private bool CheckUserLoginCached(string UserId)
    {
        bool _retValue = false;
        string sKey = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.UserCacheName");
        sKey += UserId;
        if (HttpContext.Current.Cache[sKey] == null)
        {
            _retValue = true;
        }
        else
        {
            if (Session[General.UserId] == null)
            {
                this.Cache.Remove(sKey);
                _retValue = true;
            }
            else
            {
                _retValue = false;
            }
        }
        return _retValue;
    }

    #endregion

    #region CoverageCom
    protected void ddlCoverageComMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        string selDate = ddlCoverageComDate.Text;
        ddlCoverageComDate.Items.Clear();
        CultureInfo ci = CultureInfo.CurrentCulture;
        string strDate = ddlCoverageComMonth.Text;
        int _iMonth = Convert.ToInt32(strDate.Substring(0, 2));
        int _iYear = Convert.ToInt32(strDate.Substring(2, 4));

        DateTime dtNow = new DateTime();
        dtNow = General.GetUTCDateTime().AddDays(2);

        DateTime dtEnd = new DateTime();
        dtEnd = new DateTime(_iYear, _iMonth, DateTime.DaysInMonth(_iYear, _iMonth));

        DateTime dtEndMonth = new DateTime();
        dtEndMonth = General.GetUTCDateTime().AddDays(120);

        if (dtNow.Month == _iMonth && dtNow.Year == _iYear)
        {
            //Start
            int dteDiff = dtEnd.Day - dtNow.Day;
            for (int i = 0; i <= dteDiff; i++)
            {
                DateTime dtTemp = dtNow.AddDays(i);
                string strTemp = dtTemp.Date.Day.ToString("00");
                ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd", ci), strTemp));
            }
        }
        else if (dtEndMonth.Month == _iMonth && dtEndMonth.Year == _iYear)
        {
            //End
            dtNow = new DateTime(_iYear, _iMonth, 1);

            int dteDiff = dtEndMonth.Day - 1;
            for (int i = 0; i <= dteDiff; i++)
            {
                DateTime dtTemp = dtNow.AddDays(i);
                string strTemp = dtTemp.Date.Day.ToString("00");
                ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd", ci), strTemp));
            }
        }
        else
        {
            dtNow = new DateTime(_iYear, _iMonth, 1);

            int dteDiff = dtEnd.Day - 1;
            for (int i = 0; i <= dteDiff; i++)
            {
                DateTime dtTemp = dtNow.AddDays(i);
                string strTemp = dtTemp.Date.Day.ToString("00");
                ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd", ci), strTemp));
            }
        }
        
        ddlCoverageComDate.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        ddlCoverageComDate.SelectedIndex = ddlCoverageComDate.Items.IndexOf(ddlCoverageComDate.Items.FindByValue(selDate));
    }

    private void SetCoverageComDate()
    {
        CultureInfo ci = CultureInfo.CurrentCulture;
        DateTime dtNow = new DateTime();
        dtNow = General.GetUTCDateTime().AddDays(2);

        DateTime dtEndMonth = new DateTime();
        dtEndMonth = General.GetUTCDateTime().AddDays(120);

        int mthDiff = ((dtEndMonth.Year - dtNow.Year) * 12) + dtEndMonth.Month - dtNow.Month;
        for (int m = 0; m <= mthDiff; m++)
        {
            DateTime dtTemp = dtNow.AddMonths(m);
            string strDate = dtTemp.ToString("MMyyyy", new CultureInfo("en-US"));
            ddlCoverageComMonth.Items.Add(new ListItem(dtTemp.ToString("MMMM yyyy", ci), strDate));
        }

        DateTime dtNow2 = new DateTime();
        dtNow2 = General.GetUTCDateTime().AddDays(14);
        ddlCoverageComMonth.SelectedIndex = ddlCoverageComMonth.Items.IndexOf(ddlCoverageComMonth.Items.FindByValue(dtNow2.Date.Month.ToString("00") + dtNow2.Date.Year.ToString("0000")));

        if (dtNow2.Month == dtNow.Month)
        {
            DateTime dtEnd = new DateTime();
            dtEnd = new DateTime(dtNow.Year, dtNow.Month, DateTime.DaysInMonth(dtNow.Year, dtNow.Month));

            int dteDiff = dtEnd.Day - dtNow.Day;
            for (int i = 0; i <= dteDiff; i++)
            {
                DateTime dtTemp = dtNow.AddDays(i);
                string strDate = dtTemp.Date.Day.ToString("00");
                ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd", ci), strDate));
            }
        }
        else
        {
            DateTime dtEnd = new DateTime();
            dtEnd = new DateTime(dtNow2.Year, dtNow2.Month, DateTime.DaysInMonth(dtNow2.Year, dtNow2.Month));
            dtNow = new DateTime(dtNow2.Year, dtNow2.Month, 1);
            int dteDiff = dtEnd.Day - 1;
            for (int i = 0; i <= dteDiff; i++)
            {
                DateTime dtTemp = dtNow.AddDays(i);
                string strDate = dtTemp.Date.Day.ToString("00");
                ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd", ci), strDate));
            }
        }

        ddlCoverageComDate.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        ddlCoverageComDate.SelectedIndex = ddlCoverageComDate.Items.IndexOf(ddlCoverageComDate.Items.FindByValue(dtNow2.Date.Day.ToString("00")));

    }
    #endregion

    
}
